﻿using Entity.System.DTO.Menu;
using Entity.System.View.Menu;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.System;

namespace AnQinManagermentBackendAPI.Controller.System
{
    /// <summary>
    /// 菜单表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class Menucontroller : ControllerBase
    {
        /**
         * 菜单业务接口
         */
        private readonly MenuService _menuService;

        /**
         * 构造注入
         */
        public Menucontroller(MenuService menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 获取菜单列表
        /// </summary>
        [ProducesResponseType(typeof(MenuView), 200)]
        [HttpGet]
        public async Task<IActionResult> GetMenuList([FromQuery] MenuSearchDTO menuSearchDTO)
        {
            var response = await _menuService.GetMenuList(menuSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增菜单
        /// </summary>
        /// <params name="menuAddDTO"></params>
        [HttpPost]
        public async Task<IActionResult> AddMenu([FromBody] MenuAddDTO menuAddDTO)
        {
            var response = await _menuService.AddMenu(menuAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 编辑菜单
        /// </summary>
        /// <params name="menuUpdateDTO"></params>
        [HttpPut]
        public async Task<IActionResult> PutMenu([FromBody] MenuUpdateDTO menuUpdateDTO)
        {
            var response = await _menuService.PutMenu(menuUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteMenu([FromQuery] string Id)
        {
            var response = await _menuService.DeleteMenu(Id);
            return StatusCode(response.Status, response);
        }
    }
}
